<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Svips extends Base
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $list=db('eb_member_ship')->select();
        $this->assign('list',$list);
        return $this->fetch();
    }
    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        $where=[];
        $list=db('eb_member_ship')->where($where)->select();
        $this->assign('list',$list);
        return $this->fetch();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
         $inputdata=input();

         $data['title']=$inputdata['title'];
         $data['vip_day']=$inputdata['vip_day'];
         $data['original_price']=$inputdata['original_price'];
         $data['price']=$inputdata['price'];
         $data['sort']=$inputdata['sort'];
         $data['is_free']=$inputdata['is_free'];
         $data['is_permanent']=$inputdata['is_permanent'];
         $data['is_publish']=$inputdata['is_publish'];
//         $inputmodel=model('svips');
//         $list=$inputmodel->creat($data);
        $list=db('eb_member_ship')->insert($data);
         if($list){
            $this->success('添加成功',url('svips/index'));
         }else{
            $this->error('添加失败');
         }
    }
    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        $list=db('eb_member_ship')->where(['id'=>$id])->find();
        $this->assign('list',$list);
        return $this->fetch();
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        $inputdata=input();
//        $id=input('id');
        $data['title']=$inputdata['title'];
        $data['vip_day']=$inputdata['vip_day'];
        $data['original_price']=$inputdata['original_price'];
        $data['price']=$inputdata['price'];
        $data['sort']=$inputdata['sort'];
        $data['is_free']=$inputdata['is_free'];
        $data['is_permanent']=$inputdata['is_permanent'];
        $data['is_publish']=$inputdata['is_publish'];
        $inputmodel=model('svips');
        $list=$inputmodel->edit($id,$data);
        if($list){
            $this->success('修改成功',url('svips/index'));
        }else{
            $this->error('修改失败');
        }
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function remove($id)
    {
        $inputmodel=model('svips');
        $list=$inputmodel->del($id);
        if($list){
            $this->success('删除成功',url('svips/index'));
        }else{
            $this->error('删除失败');
        }
    }
}
